﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using GCC.Container.Abstracts;

using tcm.utils;

namespace tcm.request
{
    public class BaseDto
    {
        public long id { get; set; }

        public virtual void Create()
        {
            this.id = LuanNiao.Core.IDGen.GetInstance().NextId();
        }

    }

    public class BaseExtensionDto : BaseDto
    {

        public long? create_by { get; set; }

        public DateTime? create_date { get; set; }

        public long? update_by { get; set; }

        public DateTime? update_date { get; set; }

        public new async Task Create(AbsGCCContext context, string token) {

            base.Create();
            this.create_date = DateTime.Now;
            this.update_date = DateTime.Now;
            
            if (this.create_by == null || this.create_by<=0)
            {
                var user = AuthManager.GetUserInfoByToken(context,  token);
                if (user != null)
                {
                    this.create_by = user.user_id;
                    this.update_by = user.user_id;
                }
                else
                {
                    if (this.create_by == null)
                    {
                        this.create_by = 0;
                    }
                }
            }
        }

        public new async Task Modify(AbsGCCContext context,string token)
        {
            this.update_date = DateTime.Now;
            var user = AuthManager.GetUserInfoByToken(context, token);
            if (user != null)
            {
                this.update_by = user.user_id;
            }
            else
            {
                if (this.update_by == null)
                {
                    this.update_by = 0;
                }
            }
            
        }

    }

}
